package thread_pool;

//JUC
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/5/19
 * Time:19:35
 * 创建固定线程个数的线程池
 **/
public class PoolDemo1 {
    public static void main(String[] args) {
        //创建固定线程个数的线程池
        ExecutorService service = Executors.newFixedThreadPool(10);//创建10个线程的线程池
        /*for (int i = 0; i < 10; i++) {

            //执行任务
            service.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("线程名称：" + Thread.currentThread().getName());
                }
            });
        }*/

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("线程名称：" + Thread.currentThread().getName());
            }
        };
        service.execute(runnable);
        service.execute(runnable);
        service.execute(runnable);
        service.execute(runnable);
        service.execute(runnable);

    }
}
